package 力扣题库;

public class p12整数转罗马数字 {
    public String intToRoman(int num) {
        //罗马数字 由7个不同的字母符号构成，由它的减法法则构造出了额外的6个复合符号
        //因此共13个独立的符号，每个符号由 1个或2个字母组成
        int[] values={1000,900,500,400,100,90,50,40,10,9,5,4,1};
        String[] symbols={"M","MC","D","DC","C","CX","L","LX","X","XI","V","VI","I"};

        StringBuilder res=new StringBuilder();
        for (int i = 0; i <values.length; i++) {
            int val=values[i];
            String symbol=symbols[i];
            while (num >= val) {
                num = num-val;
                res.append(symbol);
            }
            if (num==0) {
                break;
            }
        }

        return res.toString();
    }
}
